import { decrypts } from '@/utils'
import { GlobalSessionKey } from '@/constant'

export default () => {
  const setLocalToken = (key: string, value: string) => {
    window.sessionStorage.setItem(key, value)
  }
  const clearSession = () => {
    window.sessionStorage.removeItem(GlobalSessionKey)
  }

  function getAuthInfo() {
    const encryptStr = window.sessionStorage.getItem(GlobalSessionKey) ?? ''
    if (!encryptStr) return {}
    return JSON.parse(decrypts(encryptStr))
  }

  return {
    setLocalToken,
    clearSession,
    getAuthInfo,
  }
}
